Skip to content

Data and functions 1#4

Open
Hannah-Rauser-406 wants to merge 2 commits intoAmericaCampaign:masterfrom
Hannah-Rauser-406:data-and-functions-1
Open

Data and functions 1#4
Hannah-Rauser-406 wants to merge 2 commits intoAmericaCampaign:masterfrom
Hannah-Rauser-406:data-and-functions-1

Conversation

@Hannah-Rauser-406
Copy link

Having trouble getting this function to work. I have a bunch of stuff in the wrong places, but I'm not sure what proper placement would look like.
const orderInfo = { orderId: orderId, userName: userName, price: price } &
let orderId = DATA.orders.id let userName = getUserById(DATA.orders.userId).name let price = getProductById(DATA.order.productId).price

Copy link
Contributor

@jcheroske jcheroske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You wandered off into the weeds on getOrderInfo. Look at my comments and perhaps start over and just take it step by step.

if (DATA == null || DATA.products == null) {
return null
}
let mostExpProd // = undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you really want to make it explicit, you could just do:

let mostExpProd = undefined

but putting in the comment is also good form.

@@ -0,0 +1,28 @@
import DATA from '../DATA'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't import DATA! It's being passed to you.

@@ -0,0 +1,21 @@
import DATA from '../DATA'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't import DATA! You can remove this import from all of your answer files.

import getProductById from './getProductById'
import getUserById from './getUserById'

const getOrderInfo = (DATA, orderId) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function only takes one parameter: DATA. Drop the orderId param.

import getUserById from './getUserById'

const getOrderInfo = (DATA, orderId) => {
if (DATA == null || DATA.users == null || orderId == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your second test should be testing for the existence of data.orders

for (let i = 0; i < DATA.orders.length; i++) {
const orderInfo = {
orderId: orderId,
userName: userName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the userName the way you are setting it on line 19. Same with price, but use currentOrder instead of DATA.order.

let orderId = DATA.orders.id
let userName = getUserById(DATA.orders.userId).name
let price = getProductById(DATA.order.productId).price
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete lines 17-21.

}
let orderInfoArr = []

for (let i = 0; i < DATA.orders.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the first line of your for loop:

const currentOrder = DATA.orders[i]

Then go from there...


for (let i = 0; i < DATA.orders.length; i++) {
const orderInfo = {
orderId: orderId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set orderId from the currentOrder's id property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments